/**
 *
 * @author cwy
 * @since 2022/5/20
 */

export function  timestampToDate (value, type = 0){
 var time = new Date(value);
 var year = time.getFullYear();
 var month = time.getMonth() + 1;
 var date = time.getDate();
 var hour = time.getHours();
 var minute = time.getMinutes();
 var second = time.getSeconds();
 month = month < 10 ? "0" + month : month;
 date = date < 10 ? "0" + date : date;
 hour = hour < 10 ? "0" + hour : hour;
 minute = minute < 10 ? "0" + minute : minute;
 second = second < 10 ? "0" + second : second;
 var arr = [
  year + "-" + month + "-" + date,
  year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second,
  year + "年" + month + "月" + date,
  year + "年" + month + "月" + date + " " + hour + ":" + minute + ":" + second,
  hour + ":" + minute + ":" + second,
  date + "号",
  date,
  month + "月" + date + " ",
 ]
 return arr[type];
}

// 获取当前时间
 export function getTime(){
  let yy = new Date().getFullYear();
  var mm =new Date().getMonth() < 10 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1;
  var dd = new Date().getDate() <10 ? "0" + new Date().getDate() : new Date().getDate();
  let hh = new Date().getHours();
  let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
  let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
  return yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
}
// 获取当天日期
 export function getToday(){
  let yy = new Date().getFullYear();
  var mm =new Date().getMonth() < 10 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1;
  var dd = new Date().getDate() <10 ? "0" + new Date().getDate() : new Date().getDate();
  return yy+'-'+mm+'-'+dd
}

 export function getStartToday(){
  let yy = new Date().getFullYear();
  var mm =new Date().getMonth() < 10 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1;
  var dd = new Date().getDate() <10 ? "0" + new Date().getDate() : new Date().getDate();
  let hh = '00';
  let mf = '00';
  let ss = '00';
  return yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
}

export function getStartYesterday(){
  let yy = new Date().getFullYear();
  var mm =new Date().getMonth() < 10 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1;
  var dd = new Date().getDate() <10 ? "0" + new Date().getDate() : new Date().getDate() - 1;
  let hh = '00';
  let mf = '00';
  let ss = '00';
  return yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
}
 export function getLastToday(){
  let yy = new Date().getFullYear();
  var mm =new Date().getMonth() < 10 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1;
  var dd = new Date().getDate() <10 ? "0" + new Date().getDate() : new Date().getDate();
  let hh = '23';
  let mf = '59';
  let ss = '59';
  return yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
}

export function getQueryStringArgs() {
 var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
   args = {},
   items = qs.length ? qs.split("&") : [],
   item = null,
   name = null,
   value = null,
   i = 0,
   len = items.length;
 for(i = 0; i < len; i++) {
  item = items[i].split("=");
  name = decodeURIComponent(item[0]);
  value = decodeURIComponent(item[1]);
  if(name.length) {
   args[name] = value;
  }
 }
 return args;
}


export function deepCopy (obj) {
 if (obj instanceof Array || obj instanceof Object) {
  const result = Array.isArray(obj) ? [] : {}
  for (const key in obj) {
   if (obj.hasOwnProperty(key)) {
    if (typeof obj[key] === 'object' && obj[key] !== null) {
     result[key] = deepCopy(obj[key])
    } else {
     result[key] = obj[key]
    }
   }
  }
  return result
 }
 return obj
}
